<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>发布新投票</title>
<link type="text/css" rel="stylesheet" href="css/style.css" />
	<script src="http://47.106.66.89:8080/js/vue.min.js"></script>
	<script src="http://47.106.66.89:8080/js/axios.min.js"></script>
	<link  href="http://47.106.66.89:8080/js/ele-2.15.7/theme-chalk/index.css" rel="stylesheet">
	<script src="http://47.106.66.89:8080/js/ele-2.15.7/index.js"></script>
	<script src="/user/js/login.js"></script>
	<script src="/vcode/js/vcode.js"></script>
	<script src="/js/vote.js"></script>
</head>
<body>
<div id="app">
	<vote>
		<div id="voteManage" class="box">
			<h2>添加新投票</h2>
			<div class="content">
				<form method="post" action="view.html">
					<dl>
						<dt>投票内容：</dt>
						<dd>
							<input type="hidden" name="entityId" value=""/>
							<input type="text" class="input-text" v-model="vote.vname"  value=""/>
						</dd>
						<dt>投票类型：</dt>
						<dd>
							<input type="radio" v-model="vote.vtype" checked="checked" value="单选" />单选
							<input type="radio" v-model="vote.vtype" value="多选" />多选
						</dd>
						<dt>投票日期：</dt>
						<dd>
							<el-date-picker v-model="vote.startDate" type="date" placeholder="开始日期" style="width: 150px"></el-date-picker>
							至
							<el-date-picker v-model="vote.endDate" type="date" placeholder="结束日期" style="width: 150px"></el-date-picker>
						</dd>
						<dt>投票选项：</dt>
						<dd id="voteoptions">
							<p v-for="i in vote.items">
								<input type="text" class="input-text" v-model="i.iname" />
							</p>
						</dd>
						<dt></dt>
						<dd class="button">
							<input type="image" src="images/button_submit.gif"
								@click.prevent="commit"/>
							<a href="#" @click.prevent="vote.items.push({iname:''})">增加选项</a>
							<a href="index.html">取消操作</a>
						</dd>
					</dl>
				</form>
			</div>
		</div>
	</vote>
</div>

<script>
	var v = new Vue({
		el:"#app",
		data:{
			vote:{
				vname:"",
				vtype:"",
				startDate:'',
				endDate:'',
				items: [
					{iname:""},
					{iname:""},
				]
			}
		},
		methods:{
			commit(){
				//"2023-12-12T16:00:00.000Z"
				this.vote.startDate = this.vote.startDate.toLocaleDateString() + "T23:59:59.999Z";
				this.vote.endDate = this.vote.endDate.toLocaleDateString() + "T23:59:59.999Z";
				this.vote.startDate = this.vote.startDate.replace(/\//g,"-");
				this.vote.endDate = this.vote.endDate.replace(/\//g,"-");
				// post 上传 json 对象
				axios.post("/vote/tpVote/commit", this.vote).then(res=>{
					console.info(res.data);
					alert(res.data.msg)
				})
			}
		}

	})
</script>
</body>
</html>

